
#include "GUI.h"
#include "Arduino.h"
#include "app_hoodle.h"


int hoodle_num=0;

void app_hoodle_Scan(hoodle *hoodle_List)
{
    hoodle *p = hoodle_List;
    while (p)
    {
        p->x = p->x + p->x_speed;
        p->y = p->y + p->y_speed;

        if (p->x >= GUI_WIDTH)
        {
            p->x = GUI_WIDTH;
            p->x_speed = -p->x_speed;
        }
        else if (p->x <= 0)
        {
            p->x = 0;
            p->x_speed = -p->x_speed;
        }
        

        if (p->y >= GUI_HIGH)
        {
            p->y = GUI_HIGH;
            p->y_speed = -p->y_speed;
        }
        else if (p->y <= 0)
        {
            p->y = 0;
            p->y_speed = -p->y_speed;
        }
        p=p->next;
        Serial.printf("scan\n");
    }
    

}
void app_hoodle_Refresh(hoodle *hoodle_List)
{
    hoodle *p = hoodle_List;
    while (p)
    {
        DrawFillCircle(p->x,p->y,p->size);
        p=p->next;
    }
    
}
void app_hoodle_run()
{
    static hoodle *hoodle_List = NULL;

    if (hoodle_List ==NULL)
    {
        hoodle_List = add_five_hoodle(hoodle_List);
    }
    app_hoodle_Scan(hoodle_List);
    app_hoodle_Refresh(hoodle_List);

}


hoodle *del_hoodle(hoodle *hoodle_List)   //删除一个结点
{
    ;
}

hoodle *add_hoodle(hoodle *hoodle_List)   //增加一个结点
{
    ;
}

hoodle *add_five_hoodle(hoodle *hoodle_List)//增加设定好的五个节点
{
    hoodle *head;
    hoodle *p0,*p1;
    int i;

    hoodle hoodle_group[]={
        {0,64,32,4,6,6,NULL},
        {1,64,32,4,4,3,NULL},
        {2,64,32,4,5,9,NULL},
        {3,64,32,4,10,4,NULL},
        {4,64,32,4,7,4,NULL},
        {5,64,32,4,0,9,NULL},
        {6,64,32,4,5,1,NULL},
        {7,64,32,4,7,5,NULL}
    };

    p1=head=hoodle_List;
    for(i=0;i<8;i++)
    {
        p0=(hoodle *)malloc(LEN);
        *p0=hoodle_group[i];
        p0->number==++hoodle_num;

        if(head)
        {
            while (p1->next)p1=p1->next;
            p1->next=p0;
        }
        else
        {
            p1=head=p0;
        }
        Serial.printf("new %d \n",i);
    }
    return head;
}





